package org.boulderfoodrescue.webapp.client.options.volunteerinfo;

import org.boulderfoodrescue.webapp.client.managers.UserAccountManager;
import org.boulderfoodrescue.webapp.shared.UserAccount;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Widget;

public class VolunteerInfoPanel extends Composite {

  private static VolunteerinfoPanelUiBinder uiBinder = GWT
      .create(VolunteerinfoPanelUiBinder.class);

  interface VolunteerinfoPanelUiBinder extends UiBinder<Widget, VolunteerInfoPanel> {
  }

  public VolunteerInfoPanel(UserAccount user) {
    initWidget(uiBinder.createAndBindUi(this));

  }

  @UiField
  ListBox transportation;
  @UiField
  Button submit;
  
  private UserAccount user;
  
  public void setUserAccountData(UserAccount user)
  {
    this.user = user;
    transportation.setSelectedIndex(user.getTransportationAsLong().intValue());
  }
  
  @UiHandler("submit")
  public void onSubmitButtonClicked(ClickEvent event)
  {
    submit.setEnabled(false);
    submit.setText("Please wait...");
    user.setTransportationViaLong(new Long(transportation.getSelectedIndex()));
    UserAccountManager.updateUser(user);
  }
  
  public void onUserAccountUpdateComplete()
  {
    submit.setEnabled(true);
    submit.setText("Save");
  }
}
